public class DemoA {
    public static class CreateThreadDemoA extends Thread{

        //setName是调用Thread中的方法
        public CreateThreadDemoA(){
            this.setName("myThread");
        }

        //重写Thread的run方法
        @Override
        public void run() {
            while(true){
                printThreadInFo();
                try {
                    Thread.sleep(2000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }

        public static void main(String[] args) throws InterruptedException {
            //调用start方法启动线程
            new CreateThreadDemoA().start();

            //演示主线程继续向下执行
            while(true){
                printThreadInFo();
                Thread.sleep(2000);

            }
        }

        private static void printThreadInFo(){
            System.out.println("当前的线程名为: "+Thread.currentThread().getName());
        }
    }

}
